import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'dart:convert';
import 'package:vegeshop/widgets/report/browse.dart';

class NewPage extends StatefulWidget {
  final String testName;
  NewPage({Key key, @required this.testName}) : super(key: key);
  @override
  State<StatefulWidget> createState() {
    return new NewPageState();
  }
}

class NewPageState extends State<NewPage> {
  var passedCase = '';
  var failedCase = '';
  @override
  void initState() {
    super.initState();
    getCase();
    print("here");
    print(widget.testName);
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          centerTitle: true,
          title: new Text(
            "测试结果",
          ),
          backgroundColor: Colors.orange,
        ),
        body: new ListView(children: <Widget>[
          ListTile(
            leading: Icon(
              Icons.book,
              color: Colors.blue,
              size: 40,
            ),
            title: Text(failedCase == '0'?"冒烟测试通过":"冒烟测试失败"),
            subtitle: Text("PASS:$passedCase FAIL:$failedCase"),
            onTap: () {
              Navigator.of(context).push(new MaterialPageRoute(
                builder: (_) {
                  return new Browser(
                    url: "https://pabst-core-stg.pingan.com.cn:8002/report" +
                        widget.testName +
                        ".html",
                    title: "测试日志",
                  );
                },
              ));
            },
          ),
        ]));
  }

  void getCase() async {
    var url =
        "https://pabst-core-stg.pingan.com.cn:8002/api/api/bstrobot/report/testcase/" +
            widget.testName.toString();
    Response response2 = await Dio().post(url);
    var data = jsonDecode(response2.toString());
    print(data);    
    setState(() {
    passedCase = data['passed_case'];
    failedCase = data['failed_case'];
    });    
  }
}
